﻿/*----------------------------------------------------------------
// Copyright (C) 2009 
// 版权所有。 
//
// 文件名：
// 文件功能描述：设备维修信息登记
//
//
// 创建标识：
// 程序作者：翟允锋
// 修改标识：
// 修改描述：
//----------------------------------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EQT.Dal;
using System.Threading;
using EQT.Model;
using Wuqi.Webdiyer;

public partial class EquipMtReg : System.Web.UI.Page
{
    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    private DaEquipMaintainLog dalMt = new DaEquipMaintainLog();
    private DaDept dalDept = new DaDept();
    private DaEmployee dalEmp = new DaEmployee();
    private UserContext context;

    protected void Page_Load(object sender, EventArgs e)
    {
        context = Session["USER_CONTEXT"] as UserContext;
        OperationResult.Text = "";
        divResult.Visible = false;
        if (!IsPostBack)
        {
            DataSet dsDept = dalDept.Query(string.Empty);

            Utility.BindDataSet2Combox(dsDept, DdlMtDept, "Dept_Name", "Dept_ID");
            this.DdlMtDept_SelectedIndexChanged(null, null);
            CreateMtn_Date.Text = DateTime.Now.ToString("yyyy-MM-dd");
        }
        if (!string.IsNullOrEmpty(Request.QueryString["EquipID"]))
        {
            CreateEquip_ID.Text = Request.QueryString["EquipID"].ToString();
            CreateEquip_ID.Enabled = false;
        }
    }

    protected void CreateGo_Click(object sender, EventArgs e)
    {
        MoEquipMaintainLog mod = new MoEquipMaintainLog();

        try
        {
            mod.Emp_Id = CreateEmp_ID.SelectedValue;
            mod.Equip_Id = CreateEquip_ID.Text.Trim();
            mod.Mtn_Date = DateTime.Parse(CreateMtn_Date.Text.ToString());
            mod.Mtn_Info = CreateMtn_Info.Text.Trim();

            int rtn = dalMt.CreateMtLog(mod);
            if (rtn == 1)
            {
                OperationResult.Text = "维修记录登记成功！"; divResult.Visible = true;

            }
            else
            {
                OperationResult.Text = "维修记录登记失败！"; divResult.Visible = true;
            }
        }
        catch(Exception ex)
        {
            log.Error("维修记录登记失败", ex);
            OperationResult.Text = "维修记录登记用户失败！"; divResult.Visible = true;
        }

    }

    protected void DdlMtDept_SelectedIndexChanged(object sender, EventArgs e)
    {
        CreateEmp_ID.Items.Clear();

        string deptid = DdlMtDept.SelectedValue;
        if (!string.IsNullOrEmpty(deptid))
        {
            Utility.BindDataSet2Combox(dalEmp.GetEmploreeByDeptID(deptid), CreateEmp_ID, "FullName", "Emp_Id");
        }
    }

    protected void BtnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("Equipment.aspx");
    }
}
